import React, { Component } from 'react'
//import PubSub from "pubsub-js"
// import { PropTypes } from "prop-types"
import store from '../redux/store'
import {submitList} from "../redux/actions"

export default class comment extends Component {
    constructor(props) {
        super(props)
        this.state = {
            username: "ojj",
            context: "test"
        }
    }
    // static propTypes = {
    //     // addContext: PropTypes.func.isRequired,
    //     // addUsername: PropTypes.func.isRequired,
    //     submitList: PropTypes.func.isRequired
    // }
    changeContext = (event) => {
        // this.props.addContext(event.target.value)
        //PubSub.publish("addContext",event.target.value)
        this.setState({
            context: event.target.value
        })
    }
    changeUsername = (event) => {
        //console.log(event.target.value);
        // this.props.addUsername(event.target.value);
        //PubSub.publish("addUsername",event.target.value)
        this.setState({
            username: event.target.value
        })
    }
    submitList = () => {
        //console.log(event.target.value);
        const { username, context } = this.state
        const action = submitList({ username, context })
        store.dispatch(action)
        // this.props.submitList({ username, context });
        //PubSub.publish("addUsername",event.target.value)
    }

    render() {
        return (
            <div>
                评论内容<br></br>

                <textarea rows="5" cols="20" onChange={this.changeContext} />

                <div className="username">
                    用户名<br />
                    {/* <input type="text" placeholder="请输入您的用户名"
                    ref={(input) => this.inputUsername = input} /> */}
                    <input type="text" placeholder="请输入您的用户名"
                        onChange={this.changeUsername} /><br></br>
                    <button onClick={this.submitList}>提交</button>
                </div>
            </div>
        )
    }
}
